package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.beans.beancontext.BeanContextProxy;

/**
 * @author stone
 * @date 2021/11/18 17:08
 */
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor的before方法：" + beanName);
        if (bean instanceof LifeCycleBean) {
            LifeCycleBean beanTemp = (LifeCycleBean) bean;
            beanTemp.setParameter("松哥");
            return beanTemp;
        }
        if (beanName.contains("service") || beanName.contains("Service")) {
            //就可以针对所有的service组件都做一个通用的处理呢？ 可以
        }
        //可以通过bean拿到Class 👉 去制造条件
        //通过获得Class可以获得接口列表 👉 判断是否实现了XXX接口
        //。。。。

        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor的after方法: " + beanName);
        return null;
    }
}
